package com.bbx.taxi.client.widget.Drag;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baidu.mapapi.map.MapView;
import com.bbx.androidapi.util.DensityUtil;
import com.bbx.api.sdk.model.passanger.Return.Elements;
import com.bbx.api.sdk.model.passanger.Return.PriceDetail;
import com.bbx.api.sdk.model.passanger.Return.ShareDetail;
import com.bbx.api.sdk.model.passanger.Return.UsableSale;
import com.bbx.api.sdk.model.passanger.Return.CarType.CarData;
import com.bbx.api.sdk.model.passanger.Return.CarType.CarType;
import com.bbx.api.sdk.model.passanger.Return.CarType.NewData;
import com.bbx.taxi.client.R;
import com.bbx.taxi.client.R.string;
import com.bbx.taxi.client.Activity.Main.IMainContract;
import com.bbx.taxi.client.Activity.Main.MainPresenter;
import com.bbx.taxi.client.Activity.Main.MainPresenter.OnCouponFinish;
import com.bbx.taxi.client.Adapter.PayAdapter;
import com.bbx.taxi.client.Adapter.PayDetailsAdapter;
import com.bbx.taxi.client.Adapter.PayAdapter.ViewHolder;
import com.bbx.taxi.client.Bean.Attribute.MainAttribute;
import com.bbx.taxi.client.Util.CouponUtils;
import com.bbx.taxi.client.Util.DateFormat;
import com.bbx.taxi.client.Util.FormatUtil;
import com.bbx.taxi.client.Util.VersionUtils;
import com.bbx.taxi.client.Util.FastBlur.BlurBuilder;
import com.bbx.taxi.client.Util.FastBlur.BlurBuilder.OnBlurFinishListener;
import com.bbx.taxi.client.Util.FastBlur.BlurBuilder.OnSnapShotFinishListener;
import com.bbx.taxi.client.widget.pop.SharePopView.OnShareDetaiFinish;
import com.yanxuwen.loadview.LoadingDialog;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.media.Image;
import android.os.Handler;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.ViewDragHelper;
import android.text.Html;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

/** 
 * @Path com.bbx.taxi.client.widget.Drag.ThanksFeeDragLayout.java
 * @Author 严旭文
 * @Date 2016-11-28 上午9:24:50
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 */
public class ThanksFeeDragLayout  extends BaseDragLayout {
	LoadingDialog mLoadingDialog;
	
	/*-----------------------试图--------------------------------*/
	private TextView tv_title;
	private TextView tv_type;
	private TextView tv_content;
	private TextView tv_thanks_fee;
	private ListView lv_thanks;
	private ThanksAdapter mThanksAdapter;
	private List<NewData> list_data;
	public ThanksFeeDragLayout(Context context) {
		super(context);
	}

	public ThanksFeeDragLayout(Context context, AttributeSet attrs) {
		super(context, attrs, 0);
	}

	public ThanksFeeDragLayout(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	@Override
	public void initView() {
		setContentView(findViewById(R.id.desc_thanks_free));
		tv_thanks_fee=(TextView)getContentView().findViewById(R.id.tv_thanks_fee);
		list_data=new ArrayList<>();
		mThanksAdapter=new ThanksAdapter(context, list_data);
		lv_thanks=(ListView)getContentView().findViewById(R.id.lv_thanks);
		lv_thanks.setAdapter(mThanksAdapter);
		tv_content=(TextView)getContentView().findViewById(R.id.tv_content);
		tv_title=(TextView)getContentView().findViewById(R.id.tv_title);
		tv_type=(TextView)getContentView().findViewById(R.id.tv_type);
		switch(VersionUtils.getVersionType(context)){
		case bbx:
			tv_title.setText(context.getString(R.string.add_thanks_fee_remind));
			tv_type.setText(context.getString(R.string.schedule_fee));
			break;
		case tianshang:
			tv_title.setText(context.getString(R.string.add_thanks_fee_remind2));
			tv_type.setText(context.getString(R.string.schedule_fee2));
			break;
		}
	}

	MainAttribute main;
	IMainContract.Presenter mPresenter;
	/**
	 * @param thanks_fee 感谢费，单位为分
	 * @param list 车型列表
	 * @param rent_id 日租类型
	 */
	public void setDetail(final IMainContract.ViewMain mainview,final IMainContract.Presenter mPresenter,double thanks_fee,List<NewData> list,final int rent_id,String car_class_id){
		main=MainAttribute.getInstance();
		this.mPresenter=mPresenter;
		this.list_data.clear();
		this.list_data.addAll(list);
		switch(VersionUtils.getVersionType(context)){
		case bbx:
			tv_content.setText(context.getString(R.string.thanks_fee_remind,FormatUtil.onFormatPrice(thanks_fee)));
			break;
		case tianshang:
			tv_content.setText(context.getString(R.string.thanks_fee_remind2,FormatUtil.onFormatPrice(thanks_fee)));
			break;
		}
		tv_thanks_fee.setText(FormatUtil.onFormatPrice(thanks_fee));
		mThanksAdapter.setCarClassId(car_class_id);
		mThanksAdapter.notifyDataSetChanged();
		lv_thanks.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position,
					long arg3) {
				close();
				mainview.setCar(list_data.get(position).class_id,list_data.get(position).getList().get(rent_id).getSchedulePrice(DateFormat.onDate_Long(main.getTime(mPresenter.isCity()))));
			}
		});
	}
	public void setLoadView(LoadingDialog mLoadingDialog){
		this.mLoadingDialog=mLoadingDialog;
		if(mLoadingDialog!=null&&!mLoadingDialog.isShowing()){
			mLoadingDialog.show();
		}
	}
	public class ThanksAdapter extends BaseAdapter {
	    /**车型*/
		List<NewData> list;
		private Context context;
		private String car_class_id;
		private int rent_id;
		public ThanksAdapter(Context context, List<NewData> list) {
			this.list = list;
			this.context = context;
		}
		@Override
		public int getCount() {
			return list.size();
		}

		@Override
		public Object getItem(int position) {
			return list.get(position);
		}

		@Override
		public long getItemId(int position) {
			return position;

		}
		public void setCarClassId(String car_class_id) {
			this.car_class_id = car_class_id;
		}
		public void setRentId(int rent_id){
			this.rent_id=rent_id;
		}

		@Override
		public View getView(final int position, View convertView, ViewGroup parent) {
			ViewHolder viewholder;
			if (convertView == null) {
				LayoutInflater inflater = LayoutInflater.from(context);
				convertView = (View) inflater.inflate(R.layout.item_thanks_fee, null);
				viewholder = new ViewHolder();
				viewholder.tv_name1 = (TextView) convertView
						.findViewById(R.id.tv_name);
				viewholder.tv_name2 = (TextView) convertView
						.findViewById(R.id.tv_name2);
				convertView.setTag(viewholder);
			} else
				viewholder = (ViewHolder) convertView.getTag();
			  int margins=DensityUtil.dip2px(context, 5);

			TextView tv_name;
			//选中
			if(list.get(position).class_id.equals(car_class_id)){
				viewholder.tv_name1.setVisibility(View.VISIBLE);
				viewholder.tv_name2.setVisibility(View.GONE);
				tv_name=viewholder.tv_name1;
				tv_name.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.btn_bg_b));
				tv_name.setTextColor(context.getResources().getColor(R.color.white));
			}else{
				viewholder.tv_name1.setVisibility(View.GONE);
				viewholder.tv_name2.setVisibility(View.VISIBLE);
				tv_name=viewholder.tv_name2;
				tv_name.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.shape_stroke_white));
				tv_name.setTextColor(context.getResources().getColor(R.color.blue));
			}
			double thanksfee=0;
			try{
			thanksfee=list.get(position).getList().get(rent_id).getSchedulePrice(DateFormat.onDate_Long(main.getTime(mPresenter.isCity())));
			}catch(Exception e){}
			if(thanksfee>0){
				int schedule_fee_id = 0;
				switch(VersionUtils.getVersionType(context)){
				case bbx:
					schedule_fee_id=R.string.schedule_fee;
					break;
				case tianshang:
					schedule_fee_id=R.string.schedule_fee2;
					break;
				}
				tv_name.setText(list.get(position).getList().get(rent_id).car_name+"-"+context.getString(schedule_fee_id)+FormatUtil.onFormatPrice(thanksfee)+"元");
			}else{
				tv_name.setText(list.get(position).getList().get(rent_id).car_name);
			}
			//如果只有一个的时候，则显示“知道了”
			if(getCount()==1){
				tv_name.setText("知道了");
			}
			

		
			return convertView;

		}

		public class ViewHolder {
			TextView tv_name1,tv_name2;
		}
	}
	@Override
	protected void onViewStatus(boolean isOpen) {
		// TODO Auto-generated method stub
		
	}
}
